<%@page import="entity.Items"%>
<%@page import="dao.ItemsDAO"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<!-- 显示商品详情，并在右侧显示商品的浏览记录（最近5条记录） -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>欢迎光临网上商城</title>
    <style type="text/css">
	   div{
	      float:left;
	      margin-left: 30px;
	      margin-right:30px;
	      margin-top: 5px;
	      margin-bottom: 5px;
	   }
	   div dd{
	      margin:0px;
	      font-size:10pt;
	   }
	   div dd.dd_name
	   {
	      color:blue;
	   }
	   div dd.dd_city
	   {
	      color:#000;
	   }
	</style>
  </head>
  
  <body> 
  	<h1>商品详情</h1><hr>
  	<center>
  		<table width="750" height="60" cellpadding="0" cellspacing="0" border="0">
  			<tr>
  			<!-- 商品详细信息 -->
  			<%
  				Items item = new ItemsDAO().getItemsById(Integer.parseInt(request.getParameter("id")));
  				if(item!=null){
  			 %>
	  				<td width="70%" valign="top">
	  					<table>
	  						<tr>
	  							<td rowspan="4"><img src="images/<%=item.getPicture()%>" width="200" height="160"/></td>
	  						</tr>
	  						<tr>
	  							<td><b><%=item.getName() %></b></td>
	  						</tr>
	  						<tr>
	  							<td>产地：<%=item.getCity() %></td>
	  						</tr>
	  						<tr>
	  							<td>价格：￥<font color="red"><b><%=item.getPrice() %></b></font></td>
	  						</tr>
	  					</table>
	  				</td>
  			<%
  				}	
  			 %>
  			 <!-- 取得Cookie -->
  			 <%
  			 	String list = "";
  			 	// 从客户端获得Cookie集合
  			 	Cookie[]cookies = request.getCookies();
  			 	if(cookies!=null&&cookies.length>0){
	  			 	for(Cookie c:cookies){
	  			 		if(c.getName().equals("ListViewCookie")){
	  			 			list = c.getValue();
	  			 		}
	  			 		
	  			 		String[] arr = list.split(",");
	  			 		// 相同商品只在浏览记录中存放一次
	  			 		if(Arrays.binarySearch(arr, request.getParameter("id"))<0){
	  			 			list += request.getParameter("id") + ",";
	  			 		}
	  			 		// 如果浏览记录超过1000条，则清空Cookie
	  			 		if(arr!=null&&arr.length>1000){
	  			 			list = "";// 清零-置空串
	  			 		}
	  			 		Cookie cookie = new Cookie("ListViewCookie",list);
	  			 		response.addCookie(cookie);
	  			 	}
	  			 }
  			  %>
  			  
  			  <!-- 浏览过的商品 -->
  			  <td width="30%" bgcolor="#EEE" align="center">
  			  	<br /><b>您浏览过的商品</b><br />
  			  	<!-- 循环开始 -->
  			  	<%
  			  		ArrayList<Items>itemsList = new ItemsDAO().getViewList(list);
  			  		if(itemsList!=null&&itemsList.size()>0){
  			  			for(Items i:itemsList){
  			  	 %>
		  			  	<div>
		  			  		<dl>
		  			  			<dt><img src="images/<%=i.getPicture() %>" width="120" height="90" border="1" /></dt>
		  			  			<dd class="dd_name"><%=i.getName() %></dd>
		  			  			<dd class="dd_city">产地：<%=i.getCity() %>&nbsp;&nbsp;价格：￥<%=i.getPrice() %></dd>
		  			  		</dl>
		  			  	</div>
  			  	<%
  			  			}
  			  		}
  			  	 %>
  			  	<!-- 循环结束 -->
  			  </td>
  			</tr>
  		</table>
  	</center>
  </body>
</html>
